<template>
  <div class="chat-body">
    <!-- 对话框 -->
    <div v-for="(msg, msgIndex) in msgList" :key="msg.data.questionId" class="chat-item">
      <div v-if="msg.type == 'robot'" class="robot-body">
        <img src="@/assets/images/robot.png" alt="图片加载失败" class="profile" />
        <!-- 欢迎语 -->
        <div v-if="msg.flag == 1" class="welcome chat-text">
          <div class="h1">
            Hi, 我是您的智能助手-<span class="blue">智明矿通</span>
          </div>
          <div class="msg-content">{{ msg.data.answer }}</div>
        </div>

        <!-- 机器人回答  -->
        <div v-else-if="msg.flag == 2" class="answer chat-text" :class="[
          msg.data?.option?.type == 'table' ? 'robot-table' : '',
          msg.data?.option?.type == 'bar' ? 'robot-bar' : '',
          msg.data?.option?.type == 'pie' ? 'robot-pie' : '',
          msg.data?.option?.type == 'line' ? 'robot-line' : '',
          msg.data?.option?.type == 'heatmap' ? 'robot-heatmap' : '',
          msg.data?.option?.type == 'scatter' ? 'robot-scatter' : '',
        ]">
          <div v-if="msg.data.answer.length == 0">
            <svg-icon iconClass="loading" class="loadingIcon" />
            理解问题
          </div>
          <template v-else>
            <div class="answer-body">
              <div v-html="setHtml(msg)" class="answer-content"></div>
              <div class="loadingIconReal">
                <svg-icon v-show="!msg.isover" iconClass="loading" class="icon" />
                <!-- <div v-show="!msg.isover" class="point"></div> -->
              </div>
            </div>
          </template>
          <template v-if="msg.isover">
            <!-- 表格 -->
            <robot-table v-if="msg.data?.option?.type == 'table'" :columns="msg.data.option.columns"
              :data="msg.data.option.data"></robot-table>
            <!-- 柱状图 -->
            <robot-bar v-if="msg.data?.option?.type == 'bar'" :data="msg.data.option.ys" :dataX="msg.data.option.xs"
              :xName="msg.data.option.xlabel" :yName="msg.data.option.ylabel" :title="msg.data.option.title"
              :id="'bar' + msg.data.questionId"></robot-bar>
            <!-- 饼图 -->
            <robot-pie v-if="msg.data?.option?.type == 'pie'" :data="msg.data.option.xs"
              :id="'pie' + msg.data.questionId"></robot-pie>
            <!-- 折线图 -->
            <robot-line v-if="msg.data?.option?.type == 'line'" :data="msg.data.option.ys" :dataX="msg.data.option.xs"
              :names="msg.data.option.label || []" :xName="msg.data.option.xlabel" :yName="msg.data.option.ylabel"
              :title="msg.data.option.title" :id="'line' + msg.data.questionId"></robot-line>
            <!-- 热力图 -->
            <robot-heatmap v-if="msg.data?.option?.type == 'heatmap'" :data="msg.data.option.ys"
              :xName="msg.data.option.xlabel" :yName="msg.data.option.ylabel"
              :id="'heatmap' + msg.data.questionId"></robot-heatmap>
            <!-- 散点图 -->
            <robot-scatter v-if="msg.data?.option?.type == 'scatter'" :data="msg.data.option.ys"
              :xName="msg.data.option.xlabel" :yName="msg.data.option.ylabel"
              :id="'scatter' + msg.data.questionId"></robot-scatter>
          </template>
          <el-button v-if="msg.data.answer.length != 0" type="primary" link :icon="Refresh"
            @click="handleRefresh(msgIndex)" class="refresh">重新生成</el-button>
        </div>
        <el-button v-if="msgIndex == msgList.length - 1 && msg.flag !== 1 && !msg.isover" type="primary" plain
          class="stop">
          <svg-icon iconClass="stop" />
          停止生成
        </el-button>
        <!-- 每次对话下面的推荐问题 -->
        <div v-if="msg.recom" class="recommend">
          <div v-for="(item, index) in recomList" :key="index" @click="handleRecommend(item)" class="recom-item">
            <TooltipView :value="item" />
            <el-icon>
              <ArrowRight />
            </el-icon>
          </div>
        </div>
      </div>

      <div v-else-if="msg.type == 'user'" class="user-body">
        <img :src="userAcatar" alt="图片加载失败" class="profile user" />
        <div class="chat-text user-text">
          {{ msg.data.answer }}
        </div>
      </div>
    </div>
  </div>
  <!-- 底部输入框 -->
  <div class="msg-input">
    <el-button v-if="msgList.length > 0 && msgList[0].type == 'user'" type="default" plain
      class="reset-btn black black-border" @click="handleResetMsg">
      <svg-icon iconClass="duihua" />
      新建对话
    </el-button>
    <el-input ref="userMessageRef" v-model="userMessageText" :rows="6" resize="none" type="textarea"
      placeholder="输入你的问题, 通过shift+回车换行" @keydown="handleEnter">
    </el-input>
    <div class="msg-btn">
      <el-button circle plain :disabled="userMessageText.length == 0" @click="handleReset">
        <svg-icon iconClass="clear" />
      </el-button>
      <el-button type="primary" circle :disabled="userMessageText.length == 0" @click="handleEnter(false)">
        <svg-icon iconClass="send" />
      </el-button>
    </div>
    <div class="footer-txt">以上内容均由AI大模型生成，仅供参考和借鉴</div>
  </div>
</template>

<script lang="ts" setup>
import { nextTick, ref, watch, onActivated, onDeactivated } from "vue";
import { chartStor } from "@/store/chart";
import { Refresh } from "@element-plus/icons-vue";
import { uuid } from "@/utils/randomNumber";
import { marked } from "marked";

const { initChat, setChat, closeChat } = chartStor();
const props = defineProps({
  // 用户头像
  userAcatar: {
    required: true,
    type: String,
    default: "",
  }
});
onActivated(() => {
  initChat("/rv");
});
onDeactivated(() => {
  // 关闭链接
  closeChat();
});

let userAcatar = ref<string>("");
requestAnimationFrame(() => {
  userAcatar.value = JSON.parse(sessionStorage.getItem("userInfo"))?.avatar;
});
watch(() => props.userAcatar, (newV) => {
  userAcatar.value = newV;
});

/**
 * @sessionId : 会话唯一ID(新建会话或者打开新页签后sessionId会变化)
 * @type : robot(机器人) user(用户)
 * @flag : 1(欢迎语)
 * @recom : 当前回答是否展示推荐问题
 * @isover : 是否回答完毕
 * @data .answer : 文本回答
 * @data .sources : 数据源
 * @data .questionId : 每个问题唯一ID，根据此ID判断是哪一个问题的回答问题
 * @data .timestamp : 时间戳
 */
let msgList = ref<Array<any>>([
  {
    sessionId: 1,
    type: "robot",
    flag: 1,
    isover: true,
    recom: true,
    data: {
      answer: "基于对浩瀚信息进行智能解析与高效检索，我可以回答您关于矿山业务、矿山管理等知识，希望能让您的工作更加高效、便捷。",
      sources: "",
      questionId: "",
      timestamp: "",
      option: {}
    }
  },
  // {
  //   sessionId: 2,
  //   type: "robot",
  //   flag: 2,
  //   recom: true,
  //   isover: true,
  //   data: {
  //     answer: "最近一年，芍药花核准异常共计20个，表格如下：",
  //     sources: "",
  //     questionId: "",
  //     timestamp: "",
  //     option: {
  //       type: "table",
  //       columns: [
  //         { name: "发运单号", type: "number" },
  //         { name: "所属组织", type: "string" },
  //         { name: "车牌号", type: "string" },
  //         { name: "司机身份证号码", type: "string" },
  //         { name: "发运状态", type: "string" },
  //         { name: "核准状态", type: "string" },
  //         { name: "创建时间", type: "datetime" },
  //         { name: "发运时间", type: "datetime" },
  //         { name: "核准未通过原因", type: "string" },
  //         { name: "销售皮重", type: "number" },
  //         { name: "回皮时间", type: "datetime" },
  //         { name: "销售原始皮重", type: "number" },
  //         { name: "销售毛重", type: "number" },
  //         { name: "重磅时间", type: "datetime" },
  //         { name: "销售原始毛重", type: "number" },
  //         { name: "原始净重", type: "number" },
  //         { name: "进入时间", type: "datetime" },
  //         { name: "离开时间", type: "datetime" },
  //       ],
  //       data: [
  //         {
  //           发运单号: 1826208993739075585,
  //           所属组织: "1825775320750489602",
  //           车牌号: "黄辽BVLZ2P",
  //           司机身份证号码: "110010199302038844",
  //           发运状态: "异常跳秤并完成",
  //           核准状态: "未通过",
  //           创建时间: "2024-08-21T18:45:28.000",
  //           发运时间: "2024-08-21T18:45:28.000",
  //           核准未通过原因:
  //             "计量毛磅秤内核准未通过,销售数据比核对数据少20.4吨;毛磅秤间核准未通过,计量毛磅数据比核准毛磅数据多42.98吨;",
  //           销售皮重: null,
  //           回皮时间: null,
  //           销售原始皮重: null,
  //           销售毛重: 22.58,
  //           重磅时间: "2024-08-21T18:45:26.000",
  //           销售原始毛重: 42.98,
  //           原始净重: 0.0,
  //           进入时间: "2024-08-21T18:45:26.000",
  //           离开时间: "2024-08-21T18:45:27.000",
  //         },
  //       ],
  //     },
  //   },
  // },
  // {
  //   sessionId: 3,
  //   type: "robot",
  //   flag: 2,
  //   recom: true,
  //   isover: true,
  //   data: {
  //     answer: "最近一年，芍药花核准异常共计20个，表格如下：",
  //     sources: "",
  //     questionId: "",
  //     timestamp: "",
  //     option: {
  //       type: "bar",
  //       xs: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
  //       ys: [5, 20, 36, 10, 10, 20],
  //     }
  //   },
  // },
  // {
  //   sessionId: 3,
  //   type: "robot",
  //   flag: 2,
  //   recom: true,
  //   isover: true,
  //   data: {
  //     answer: "最近一年，芍药花核准异常共计20个，表格如下：",
  //     sources: "",
  //     questionId: "",
  //     timestamp: "",
  //     option: {
  //       type: "pie",
  //       xs: [
  //         {
  //           value: 12,
  //           percentage: 10,
  //           name: "人",
  //           nm: "(个)",
  //         },
  //         {
  //           value: 20,
  //           percentage: 20,
  //           name: "机动车",
  //           nm: "(个)",
  //         },
  //         {
  //           value: 30,
  //           percentage: 50,
  //           name: "非机动车",
  //           nm: "(个)",
  //         },
  //         {
  //           value: 20,
  //           percentage: 20,
  //           name: "其他",
  //           nm: "(个)",
  //         },
  //       ],
  //     },
  //   },
  // },
  // {
  //   sessionId: 4,
  //   type: "robot",
  //   flag: 2,
  //   recom: true,
  //   isover: true,
  //   data: {
  //     answer: "最近一年，芍药花核准异常共计20个，表格如下：",
  //     sources: "",
  //     questionId: "",
  //     timestamp: "",
  //     option: {
  //       type: "line",
  //       xs: ["03-15", "03-16", "03-17", "03-18", "03-19", "03-20", "03-21"],
  //       ys: [
  //         [64, 159, 112, 86, 151, 131, 118],
  //         [124, 30, 77, 97, 67, 75, 70],
  //       ],
  //       names: ["芍药花磅秤异常", "芍药花核准异常"],
  //     },
  //   },
  // },
  // {
  //   sessionId: 5,
  //   type: "robot",
  //   flag: 2,
  //   recom: true,
  //   isover: true,
  //   data: {
  //     answer: "最近一年，芍药花核准异常共计20个，表格如下：",
  //     sources: "",
  //     questionId: "",
  //     timestamp: "",
  //     option: {
  //       type: "heatmap",
  //       ys: [
  //         [0, 0, 0.5],
  //         [0, 1, 0.4489576875],
  //         [0, 2, 0.393152],
  //         [0, 3, 0.3313716875],
  //         [0, 4, 0.26524799999999993],
  //         [0, 5, 0.1982421875],
  //         [0, 6, 0.134768],
  //         [0, 7, 0.07944918750000002],
  //         [0, 8, 0.03651199999999999],
  //         [0, 9, 0.009312687499999972],
  //         [0, 10, 0],
  //         [0, 11, 0.009312687500000028],
  //         [0, 12, 0.03651199999999999],
  //         [0, 13, 0.07944918750000007],
  //         [0, 14, 0.1347679999999999],
  //         [0, 15, 0.1982421875],
  //         [0, 16, 0.26524800000000015],
  //         [0, 17, 0.33137168749999946],
  //         [0, 18, 0.39315199999999983],
  //         [0, 19, 0.44895768749999915],
  //         [0, 20, 0.5],
  //         [1, 0, 0.5],
  //         [1, 1, 0.448928734375],
  //         [1, 2, 0.3929379356077344],
  //         [1, 3, 0.33070599025141967],
  //         [1, 4, 0.2637986928971875],
  //         [1, 5, 0.19565118210601806],
  //         [1, 6, 0.13068486618535158],
  //         [1, 7, 0.07355933881037724],
  //         [1, 8, 0.028559284490000003],
  //         [1, 9, -0.0008836261225146913],
  //         [1, 10, -0.012533851074218783],
  //         [1, 11, -0.005560102112481702],
  //         [1, 12, 0.01939152015968748],
  //         [1, 13, 0.06025938097299566],
  //         [1, 14, 0.11376315592589831],
  //         [1, 15, 0.17573566536331175],
  //         [1, 16, 0.24158969860000012],
  //         [1, 17, 0.30691982798864204],
  //         [1, 18, 0.368239212832578],
  //         [1, 19, 0.4238513931432255],
  //         [1, 20, 0.4748570732421875],
  //         [2, 0, 0.5],
  //         [2, 1, 0.44889984831267576],
  //         [2, 2, 0.39272399999999996],
  //         [2, 3, 0.3300395527561133],
  //         [2, 4, 0.26234529213999996],
  //         [2, 5, 0.1930484236450195],
  //         [2, 6, 0.126576226595],
  //         [2, 7, 0.06762262986689455],
  //         [2, 8, 0.020529709439999988],
  //         [2, 9, -0.011195892228261783],
  //         [2, 10, -0.02523162499999998],
  //         [2, 11, -0.02065276802794913],
  //         [2, 12, 0.001988755100000017],
  //         [2, 13, 0.040720483042832156],
  //         [2, 14, 0.09234044521499996],
  //         [2, 15, 0.15274311212158204],
  //         [2, 16, 0.21738026752000011],
  //         [2, 17, 0.2818568024083003],
  //         [2, 18, 0.3426614308399999],
  //         [2, 19, 0.39803232756548745],
  //         [2, 20, 0.4489576875],
  //         [3, 0, 0.5],
  //         [3, 1, 0.4488712633922571],
  //         [3, 2, 0.39251160858617185],
  //         [3, 3, 0.32937579687499996],
  //         [3, 4, 0.26089311573468743],
  //         [3, 5, 0.19043961053085323],
  //         [3, 6, 0.12244506253519527],
  //         [3, 7, 0.06163471325132086],
  //         [3, 8, 0.012405735049999977],
  //         [3, 9, -0.02166155188615604],
  //         [3, 10, -0.03815771630859377],
  //         [3, 11, -0.036063506339292006],
  //         [3, 12, -0.01583439359781258],
  //         [3, 13, 0.02064962898107303],
  //         [3, 14, 0.0702689956391796],
  //         [3, 15, 0.12898426259613038],
  //         [3, 16, 0.1922905491600001],
  //         [3, 17, 0.25580672514738356],
  //         [3, 18, 0.3159993446128905],
  //         [3, 19, 0.37104132588805583],
  //         [3, 20, 0.4218053779296875],
  //       ],
  //     },
  //   },
  // },
  // {
  //   sessionId: 6,
  //   type: "robot",
  //   flag: 2,
  //   recom: true,
  //   isover: true,
  //   data: {
  //     answer: "最近一年，芍药花核准异常共计20个，表格如下：",
  //     sources: "",
  //     questionId: "",
  //     timestamp: "",
  //     option: {
  //       type: "scatter",
  //       xlable: "KW",
  //       ylable: "COP",
  //       ys: [
  //         [
  //           [1, 80],
  //           [2, 45],
  //           [3, 75],
  //           [4, 55],
  //           [5, 65],
  //         ],
  //         [
  //           [1, 100],
  //           [2, 65],
  //           [3, 95],
  //           [4, 75],
  //           [5, 85],
  //         ],
  //       ],
  //     }
  //   },
  // },
]);

// 监听他的变化
// const updateRecomStatus = () => {
//   if (msgList.value.length > 0) {
//     msgList.value.forEach((msg, index) => {
//       msg.recom = index === msgList.value.length - 1;
//     });
//   }
// };
// updateRecomStatus();
// watch(
//   msgList,
//   () => {
//     updateRecomStatus();
//   },
//   { deep: true }
// );
let recomList = ref<Array<any>>([
  "采用折线图展示最近7天所有煤厂的报警总次数？",
  "采用折线图展示最近7天所有煤厂的发运量是多少？",
  "采用柱状图展示最近7天芍药花核准异常的有多少个？",
]);
function handleRecommend(item) {
  userMessageText.value = item;
  userMessageRef.value.focus();
}
let userMessageRef = ref(null);
let userMessageText = ref<string>("");
// 发送消息
// 会话唯一id, 没打开一个页签都会生成一个唯一id
const sessionId = ref<string>(uuid());
function handleEnter(e) {
  requestAnimationFrame(() => {
    if (!userMessageText.value.length || (msgList.value.length > 0 && !msgList.value[msgList.value.length - 1].isover)) {
      return false;
    }
    if (e.keyCode == 13 && !e.shiftKey) {
      e.preventDefault();
      // 按下回车且没按shift键
      // 去除欢迎语
      if (msgList.value.length && msgList.value[0].flag == 1 && msgList.value[0].type == "robot") {
        msgList.value = JSON.parse(JSON.stringify(msgList.value.slice(1)));
      }
      // 每个问题唯一ID，根据此ID判断是哪一个问题的回答
      const questionId = uuid();
      msgList.value.push({
        sessionId: sessionId.value,
        type: "user",
        flag: 1,
        data: {
          answer: userMessageText.value.replace(/\s/g, ""),
          questionId: "user:" + questionId,
          timestamp: "",
        }
      });
      // 请求接口,在回答前先插入一条加载中的空数据
      msgList.value.push({
        sessionId: sessionId.value,
        type: "robot",
        flag: 2,
        isover: false,
        recom: false,
        data: {
          answer: "",
          sources: "",
          questionId: questionId,
          timestamp: "",
          option: {}
        }
      });
      const params = {
        sessionId: sessionId.value,
        questionId: questionId,
        userMessageText: userMessageText.value,
        callBack
      }
      setChat(params);
      userMessageText.value = "";
    } else if (!e) {
      // 按下发送按钮
      // 去除欢迎语
      if (msgList.value.length && msgList.value[0].flag == 1 && msgList.value[0].type == "robot") {
        msgList.value = msgList.value.slice(1);
      }
      // 每个问题唯一ID，根据此ID判断是哪一个问题的回答
      const questionId = uuid();
      msgList.value.push({
        sessionId: sessionId.value,
        type: "user",
        flag: 1,
        data: {
          answer: userMessageText.value.replace(/\s/g, ""),
          questionId: "user:" + questionId,
          timestamp: "",
        }
      });
      // 请求接口,在回答前先插入一条加载中的空数据
      msgList.value.push({
        sessionId: sessionId.value,
        type: "robot",
        flag: 2,
        isover: false,
        recom: false,
        data: {
          answer: "",
          sources: "",
          questionId: questionId,
          timestamp: "",
          option: {}
        }
      });
      const params = {
        sessionId: sessionId.value,
        questionId: questionId,
        userMessageText: userMessageText.value,
        callBack
      }
      setChat(params);
      userMessageText.value = "";
    }
    scrollToBtm();
  });
}
// 滚动到底部
function scrollToBtm() {
  nextTick(() => {
    // 每次滚动到最下面
    const scrollBox = document.querySelector(".chat-body");
    scrollBox.scrollTo({
      top: scrollBox.scrollHeight,
      behavior: 'smooth' // 可选，平滑滚动效果
    });
  });
}
// 重新生成
function handleRefresh(index) {
  userMessageText.value = msgList.value[index - 1].data.answer;
  msgList.value.splice(index, 1);
  msgList.value.splice(index - 1, 1);
  handleEnter(false);
}
// 回调函数接受返回值
function callBack(val, msg) {
  // console.log("接收到了", val);
  if (msg == "error") {
    // 连接超时, 清除未接收完的信息
    msgList.value = msgList.value.filter((item, index) => {
      return (item.isover == true || (item.type == "user" && index < msgList.value.length - 2));
    });
    return false;
  }
  // console.log("结果", val)
  const { data, type, sessionId } = val;
  if (type == "reply") {
    const robotList = msgList.value.filter(item => {
      return item.type == "robot";
    })
    robotList.forEach((item, index) => {
      if (item.type == "robot" && item.data.questionId == data.questionId) {
        item.isover = false;
        item.data.answer += data.answer;
        item.data.questionId = data.questionId;
        item.timestamp = data.timestamp;
        if (data.option !== null) {
          item.data.option = Object.assign({}, data.option);
        }
      }
    });
  } else if (type == "recommendQuestion") {
    // 推荐问题
    recomList.value = data.questions;
    msgList.value.forEach((item, index) => {
      if (item.data.questionId == data.questionId) {
        item.isover = true;
      }
      if (index == msgList.value.length - 1) {
        item.recom = true;
      } else {
        item.recom = false;
      }
    });
  }
  scrollToBtm();
}
// 将富文本解析成html
function setHtml(item) {
  if (!item.data.answer) {
    return false
  }
  const htmlString: any = marked(item.data.answer);
  const robotList = msgList.value.filter(msg => {
    return msg.type == "robot";
  });
  let robotIndex = null;
  robotList.forEach((msg, index) => {
    if (msg.data.questionId == item.data.questionId && !item.isover) {
      robotIndex = index;
    }
  })
  if (robotIndex !== null) {
    nextTick(() => {
      const dom = document.querySelectorAll(".answer-content")[robotIndex];
      const loadingIcon: any = document.querySelectorAll(".loadingIconReal")[robotIndex];
      if (!!dom) {
        const lastTextNode = getLastTextNode(dom);
        // 在最后一个文本节点加文字
        const tempNode = document.createTextNode('|');
        if (lastTextNode) {
          lastTextNode.parentNode.insertBefore(tempNode, lastTextNode.nextSibling);
        } else {
          dom.appendChild(tempNode);
        }

        //根据文本节点设置光标位置
        const range = document.createRange();
        //选中文本对象
        range.setStart(tempNode, 0);
        range.setEnd(tempNode, 0);

        // 获取相对视口位置
        const rect = range.getBoundingClientRect();
        // 获取容器相对视口位置
        const containerRect = dom.getBoundingClientRect();
        const x = rect.left - containerRect.left;
        // const y = rect.top - containerRect.top + 14;
        const y = rect.top - containerRect.top;
        if (!!loadingIcon) {
          // loadingIcon.style.left = x + "px";
          // loadingIcon.style.top = y - 5 + "px";
          loadingIcon.style.transform = `translate(${x}px, ${y}px)`;
        }
        tempNode.remove();
      }
    });
  }
  return htmlString;
}
// 获取最后一个文本节点
function getLastTextNode(node) {
  if (node.nodeType === Node.TEXT_NODE && node.data != "\n") {
    return node;
  }
  let childNodes = node.childNodes;
  for (let i = childNodes.length - 1; i >= 0; i--) {
    let lastTextNode = getLastTextNode(childNodes[i]);
    if (lastTextNode) {
      return lastTextNode;
    }
  }
  return null;
}
// 新建对话
function handleResetMsg() {
  msgList.value = [{
    sessionId: 1,
    type: "robot",
    flag: 1,
    isover: true,
    recom: true,
    data: {
      answer: "基于海量数据记忆、高效算力和自然对话能力，我可以回答您关于矿山政策、行业标准等专业知识，希望能让您的工作更加高效、便捷。",
      sources: "",
      questionId: "",
      timestamp: "",
    }
  }];
  sessionId.value = uuid();
}
// 输入框重置
function handleReset() {
  userMessageText.value = "";
}
</script>

<style lang="scss" scoped>
.chat-body {
  height: calc(100% - 350px);
  margin-top: 53px;
  font-family: PingFang SC, PingFang SC-Regular;
  padding-right: 18.2vw;
  margin-bottom: 10px;
  overflow-y: auto;

  .chat-item {
    .chat-text {
      width: calc(100% - 55px);
    }

    .profile {
      width: 36px;
      height: 36px;
      margin-right: 15px;

      &.user {
        border-radius: 50%;
      }
    }

    .robot-body {
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      margin-top: 20px;

      .welcome {
        .h1 {
          line-height: 24px;
          font-size: 24px;
          font-family: PingFang SC, PingFang SC-Medium;
          font-weight: 600;
          text-align: left;
          color: #1a202c;
        }

        .msg-content {
          font-size: 16px;
          font-weight: 400;
          text-align: left;
          color: #1a202c;
          margin-top: 10px;
        }
      }

      :deep(ol) {
        padding-left: 26px;
      }

      .answer {
        background: #ffffff;
        border: 1px solid #d4d5db;
        border-radius: 16px;
        box-shadow: 0px 2px 14px 0px rgba(0, 0, 0, 0.06);
        padding: 24px 32px;
        font-family: PingFang SC, PingFang SC-Regular;
        font-size: 16px;
        font-weight: 400;
        text-align: left;
        color: #292929;

        .loadingIcon {
          color: #2D65F7;
          animation: circle 1s infinite;
        }

        .answer-body {
          position: relative;
          display: flex;

          .loadingIconReal {
            position: absolute;
          }

          .loadingIconReal {

            .icon {
              color: #2D65F7;
              animation: circle 1s infinite;
            }

            .point {
              width: 6px;
              height: 6px;
              border-radius: 50%;
              animation: pointAni .8s infinite linear;
            }
          }
        }

        pre {
          font-family: inherit;
          white-space: wrap;
        }

        .refresh {
          margin-top: 10px;
          margin-left: -10px;
          width: 100px;
          height: 32px;

          &:hover {
            color: #2D65F7;
            background: #f6f7f9;
          }
        }
      }

      .stop {
        margin: 10px 0 0 50px;
        border-radius: 8px;
      }
    }

    .recommend {
      width: 100%;

      .recom-item {
        display: flex;
        align-items: center;
        max-width: calc(100% - 50px);
        width: fit-content;
        height: 40px;
        line-height: 40px;
        background: #ffffff;
        border: 1px solid #d4d5db;
        border-radius: 10px;
        box-shadow: 0px 2px 14px 0px rgba(0, 0, 0, 0.06);
        font-size: 16px;
        font-weight: 400;
        padding: 0 10px;
        margin: 10px 0 10px 50px;
        cursor: pointer;
        user-select: none;
        font-size: 16px;
        font-family: PingFang SC, PingFang SC-Regular;
        font-weight: 400;
        text-align: justify;
        color: #292929;

        &:nth-child(1) {
          margin-top: 20px;
        }

        &:hover {
          background: rgba(242, 242, 242, 0.4);
          border: 1px solid #d4d5db;
          border-radius: 10px;
          box-shadow: 0px 2px 14px 0px rgba(0, 0, 0, 0.11);
        }

        :deep(ol) {
          padding-left: 0;

          li {
            list-style: none;
          }
        }
      }
    }

    .user-body {
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      margin-top: 20px;

      .user-text {
        font-family: inherit;
        padding: 6px 0;
        font-size: 16px;
        font-weight: 400;
        text-align: left;
        color: #292929;
      }
    }
  }
}

.msg-input {
  position: relative;
  font-family: PingFang SC, PingFang SC-Regular;
  padding-right: 18.2vw;

  .reset-btn {
    border-radius: 11px;
    box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.06);
    margin-bottom: 12px;

    .svg-icon {
      transform: rotateY(180deg);
      font-size: 20px;
    }
  }

  :deep(.el-textarea) {
    border-radius: 16px;
    box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.11);

    .el-textarea__inner {
      border-radius: 16px;
      color: #292929;
      padding: 11px;
    }
  }

  .footer-txt {
    font-size: 14px;
    font-weight: 400;
    text-align: left;
    color: #8d949e;
    margin-top: 16px;
  }

  .msg-btn {
    position: absolute;
    right: calc(18.2vw + 20px);
    bottom: 45px;

    .svg-icon {
      margin-right: 0;
    }
  }
}

.robot-table {
  overflow: hidden;
  max-height: 500px;
}

.robot-bar,
.robot-line,
.robot-heatmap,
.robot-scatter {
  overflow: hidden;
  // height: 480px;
}

.robot-pie {
  width: 100%;
  // height: 420px;
}

@keyframes circle {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@keyframes pointAni {
  0% {
    background-color: #e5e5e5;
  }

  100% {
    background-color: #000000;
  }
}
</style>